var api = require("../../api/api.js");
var storageManage = require("../../manage/storageManage.js");
var utils = require("../../utils/utils.js");
var event = require("../../event/event.js");

const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    orderHave: true,
    balance: 0,
    mPageNum: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList();
  },
  //上拉加载
  onReachBottom: function () {
    this.setData({
      isHidden: false
    });
    this.data.mPageNum += 1;
    this.getList()
  },

  //获取列表
  getList: function () {
    var that = this;
    wx.showLoading()
    api.default.api('credit_order', {
      "page": that.data.mPageNum,
      "time": that.data.time
    }, function (data) {
      wx.hideLoading()
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({
        isHidden: true
      });
      if (data.data.length == 0) { //没有数据且是第一页

        if (that.data.mPageNum <= 0) {
          that.setData({
            orderHave: false
          })
        } else {
          that.data.mPageNum -= 1;
        }
        return;
      }
      that.setData({
        orderList: that.data.orderList.concat(data.data)
      });
      wx.hideNavigationBarLoading()

    }, function () {
      wx.stopPullDownRefresh() //停止下拉刷新
      wx.hideNavigationBarLoading()
      wx.hideLoading()
    });
  }

})